<?php

namespace App\Http\Controllers;

use App\Models\Pictures;
use Dingo\Api\Routing\Helpers;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Support\Facades\Storage;

class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests,Helpers;


    public function send_message($phone,$message)
    {
        $username='70212677';
        $password = '59807df20e02cbbb766bf0f8426e3360';
        $url="http://api.duanxin.cm/?action=send&username={$username}&password={$password}&phone={$phone}&content={$message}&encode=utf8";

        return $this->https_request($url);
    }
    //curl
    public function https_request($url,$data = null){
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,false);
        curl_setopt($curl,CURLOPT_SSL_VERIFYHOST,false);
        curl_setopt($curl,CURLOPT_FOLLOWLOCATION,1);
        if (!empty($data)){
            curl_setopt($curl, CURLOPT_POST, 1);
            curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        }
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $output = curl_exec($curl);
        curl_close($curl);
        return $output;
    }

    public function upload_img($pic,$path=null,$type,$sort=0)
    {
        $picpath = $pic->store($path);
        $img = [
            'pic_path'=>$picpath,
            'pic_type'=>$type,
            'sort' =>$sort,
        ];
        if($picture= Pictures::create($img)){
            return ['status'=>1,'message'=>"保存成功",'img'=>$picture];
        }else {
            return ['status' => 0, 'message' => "fail"];
        }
    }
}
